package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.course.dto.bo.CommonRespBO;
import com.ruoyi.course.dto.bo.CourseClassBO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CourseClass;
import com.ruoyi.course.service.ICourseClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教室Controller
 *
 * @author mac
 * @date 2023-03-11
 */
@RestController @RequestMapping("/course/courseClass") public class CourseClassController extends BaseController {
    @Autowired private ICourseClassService courseClassService;

    /**
     * 查询教室列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseClass:list')") @GetMapping("/list") public TableDataInfo list(
        CourseClass courseClass) {
        startPage();
        List<CourseClassBO> list = courseClassService.selectCourseClassList(courseClass);
        return getDataTable(list);
    }

    @GetMapping("/listFloorName") public AjaxResult listFloorName() {
        startPage();
        List<CommonRespBO> list = courseClassService.listFloorName();
        return AjaxResult.success(list);
    }

    /**
     * 导出教室列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseClass:export')") @Log(title = "教室", businessType = BusinessType.EXPORT)
    @PostMapping("/export") public void export(HttpServletResponse response, CourseClass courseClass) {
        List<CourseClassBO> list = courseClassService.selectCourseClassList(courseClass);
        ExcelUtil<CourseClassBO> util = new ExcelUtil<CourseClassBO>(CourseClassBO.class);
        util.exportExcel(response, list, "教室数据");
    }

    /**
     * 获取教室详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseClass:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(
        @PathVariable("id") Long id) {
        return AjaxResult.success(courseClassService.selectCourseClassById(id));
    }

    /**
     * 新增教室
     */
    @PreAuthorize("@ss.hasPermi('course:courseClass:add')") @Log(title = "教室", businessType = BusinessType.INSERT)
    @PostMapping public AjaxResult add(@RequestBody CourseClassBO classBO) {
        return toAjax(courseClassService.insertCourseClass(classBO));
    }

    /**
     * 修改教室
     */
    @PreAuthorize("@ss.hasPermi('course:courseClass:edit')") @Log(title = "教室", businessType = BusinessType.UPDATE)
    @PutMapping public AjaxResult edit(@RequestBody CourseClass courseClass) {
        return toAjax(courseClassService.updateCourseClass(courseClass));
    }

    /**
     * 删除教室
     */
    @PreAuthorize("@ss.hasPermi('course:courseClass:remove')") @Log(title = "教室", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(courseClassService.deleteCourseClassByIds(ids));
    }
}
